package com.gnerv.sylvanas.business.manage.controller;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.business.manage.logic.ConfigLogicService;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigDTO;
import com.gnerv.sylvanas.business.manage.model.dto.ConfigUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/api/manage/config")
public class ConfigController {

    private final ConfigLogicService configLogic;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody ConfigCreateDTO configCreateDTO) {
        return configLogic.create(configCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return configLogic.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody ConfigUpdateDTO configUpdateDTO) {
        return configLogic.updateByUkId(configUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<ConfigDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return configLogic.selectByUkId(ukId);
    }

    @GetMapping(value = "/list")
    public RestResult<List<ConfigDTO>> selectListByName(@RequestParam(required = false, value = "name") String name) {
        return configLogic.selectListByName(name);
    }


}
